home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbpxen / custedit.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-23  |  12.2 KB  |  445 lines

  1. VERSION 2.00
  2. Begin Form custedit 
  3.    Caption         =   "Customer View/Edit"
  4.    ClientHeight    =   5130
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   7695
  8.    Height          =   5535
  9.    Left            =   1035
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5130
  13.    ScaleWidth      =   7695
  14.    Top             =   1140
  15.    Width           =   7815
  16.    Begin CommandButton ButtonDone 
  17.       Caption         =   "E&xIt"
  18.       FontBold        =   -1  'True
  19.       FontItalic      =   0   'False
  20.       FontName        =   "MS Sans Serif"
  21.       FontSize        =   12
  22.       FontStrikethru  =   0   'False
  23.       FontUnderline   =   0   'False
  24.       Height          =   615
  25.       Left            =   6120
  26.       TabIndex        =   19
  27.       Top             =   4200
  28.       Width           =   975
  29.    End
  30.    Begin CommandButton ButtonDelete 
  31.       Caption         =   "&Delete"
  32.       Height          =   615
  33.       Left            =   4440
  34.       TabIndex        =   22
  35.       Top             =   4200
  36.       Visible         =   0   'False
  37.       Width           =   1095
  38.    End
  39.    Begin CommandButton ButtonCancel 
  40.       Caption         =   "&Cancel"
  41.       Height          =   615
  42.       Left            =   1920
  43.       TabIndex        =   21
  44.       Top             =   4200
  45.       Visible         =   0   'False
  46.       Width           =   1095
  47.    End
  48.    Begin CommandButton ButtonOK 
  49.       Caption         =   "&OK"
  50.       Height          =   615
  51.       Left            =   360
  52.       TabIndex        =   20
  53.       Top             =   4200
  54.       Visible         =   0   'False
  55.       Width           =   975
  56.    End
  57.    Begin CommandButton ButtonNew 
  58.       Caption         =   "&Add"
  59.       Height          =   495
  60.       Left            =   6120
  61.       TabIndex        =   18
  62.       Top             =   3240
  63.       Width           =   975
  64.    End
  65.    Begin TextBox Zip 
  66.       Height          =   375
  67.       Left            =   2160
  68.       TabIndex        =   6
  69.       Text            =   " "
  70.       Top             =   2880
  71.       Width           =   1335
  72.    End
  73.    Begin TextBox city 
  74.       Height          =   375
  75.       Left            =   2160
  76.       TabIndex        =   5
  77.       Text            =   " "
  78.       Top             =   2400
  79.       Width           =   3375
  80.    End
  81.    Begin CommandButton ButtonEdit 
  82.       Caption         =   "&Edit"
  83.       Height          =   495
  84.       Left            =   6120
  85.       TabIndex        =   17
  86.       Top             =   2280
  87.       Width           =   975
  88.    End
  89.    Begin TextBox address 
  90.       Height          =   375
  91.       Left            =   2160
  92.       TabIndex        =   4
  93.       Text            =   " "
  94.       Top             =   1920
  95.       Width           =   3375
  96.    End
  97.    Begin CommandButton ButtonLast 
  98.       Caption         =   "&Last"
  99.       Height          =   375
  100.       Left            =   6720
  101.       TabIndex        =   16
  102.       Top             =   1560
  103.       Width           =   735
  104.    End
  105.    Begin CommandButton ButtonFirst 
  106.       Caption         =   "&First"
  107.       Height          =   375
  108.       Left            =   5880
  109.       TabIndex        =   15
  110.       Top             =   1560
  111.       Width           =   735
  112.    End
  113.    Begin TextBox firstname 
  114.       Height          =   375
  115.       Left            =   2160
  116.       TabIndex        =   3
  117.       Text            =   " "
  118.       Top             =   1440
  119.       Width           =   2055
  120.    End
  121.    Begin CommandButton ButtonNext 
  122.       Caption         =   "&Next"
  123.       Height          =   375
  124.       Left            =   6720
  125.       TabIndex        =   14
  126.       Top             =   960
  127.       Width           =   735
  128.    End
  129.    Begin CommandButton ButtonPrior 
  130.       Caption         =   "&Prior"
  131.       Height          =   375
  132.       Left            =   5880
  133.       TabIndex        =   13
  134.       Top             =   960
  135.       Width           =   735
  136.    End
  137.    Begin TextBox lastname 
  138.       Height          =   375
  139.       Left            =   2160
  140.       TabIndex        =   2
  141.       Text            =   " "
  142.       Top             =   960
  143.       Width           =   2055
  144.    End
  145.    Begin TextBox custnumber 
  146.       Height          =   375
  147.       Left            =   2160
  148.       TabIndex        =   1
  149.       Text            =   " "
  150.       Top             =   480
  151.       Width           =   1215
  152.    End
  153.    Begin CommandButton ButtonFind 
  154.       Caption         =   "&Get"
  155.       Height          =   495
  156.       Left            =   6120
  157.       TabIndex        =   11
  158.       Top             =   240
  159.       Width           =   975
  160.    End
  161.    Begin Label total_spent 
  162.       BorderStyle     =   1  'Fixed Single
  163.       Caption         =   " "
  164.       Height          =   375
  165.       Left            =   4440
  166.       TabIndex        =   26
  167.       Top             =   3480
  168.       Width           =   1095
  169.    End
  170.    Begin Label Label8 
  171.       Caption         =   "YTD Spent:"
  172.       Height          =   255
  173.       Left            =   3120
  174.       TabIndex        =   25
  175.       Top             =   3480
  176.       Width           =   1095
  177.    End
  178.    Begin Label tapes_out 
  179.       BorderStyle     =   1  'Fixed Single
  180.       Caption         =   " "
  181.       Height          =   375
  182.       Left            =   2160
  183.       TabIndex        =   24
  184.       Top             =   3480
  185.       Width           =   855
  186.    End
  187.    Begin Label Label7 
  188.       Caption         =   "Tapes out:"
  189.       Height          =   255
  190.       Left            =   720
  191.       TabIndex        =   23
  192.       Top             =   3480
  193.       Width           =   1335
  194.    End
  195.    Begin Label Label6 
  196.       Caption         =   "Zip:"
  197.       Height          =   255
  198.       Left            =   720
  199.       TabIndex        =   10
  200.       Top             =   3000
  201.       Width           =   975
  202.    End
  203.    Begin Label Label5 
  204.       Caption         =   "City:"
  205.       Height          =   375
  206.       Left            =   720
  207.       TabIndex        =   9
  208.       Top             =   2520
  209.       Width           =   1215
  210.    End
  211.    Begin Label Label4 
  212.       Caption         =   "Address:"
  213.       Height          =   255
  214.       Left            =   720
  215.       TabIndex        =   8
  216.       Top             =   2040
  217.       Width           =   1215
  218.    End
  219.    Begin Label Label3 
  220.       Caption         =   "First name:"
  221.       Height          =   255
  222.       Left            =   720
  223.       TabIndex        =   7
  224.       Top             =   1560
  225.       Width           =   1335
  226.    End
  227.    Begin Label Label2 
  228.       Caption         =   "Last name:"
  229.       Height          =   255
  230.       Left            =   720
  231.       TabIndex        =   0
  232.       Top             =   1080
  233.       Width           =   1335
  234.    End
  235.    Begin Label Label1 
  236.       Caption         =   "Number:"
  237.       Height          =   375
  238.       Left            =   720
  239.       TabIndex        =   12
  240.       Top             =   600
  241.       Width           =   975
  242.    End
  243. Dim iMode As Integer
  244. Dim blankcustrec As CUST
  245. Dim savecustrec As CUST
  246. Const EDIT_MODE = 0
  247. Const ADD_MODE = 1
  248. Const VIEW_MODE = 2
  249. Sub ButtonCancel_Click ()
  250.     If iMode = ADD_MODE Then
  251.         custrec = savecustrec
  252.         rc = GetCustomerRec(DBKEYED)
  253.         If rc Then
  254.             rc = GetCustomerRec(DBFIRST)
  255.         End If
  256.     End If
  257.     FieldsToForm
  258.     SetEditMode VIEW_MODE
  259. End Sub
  260. Sub ButtonDelete_Click ()
  261.     '
  262.     '  check if user pressed OK or CANCEL
  263.     '
  264.     Msg$ = "OK to delete?"
  265.     rc = MsgBox(Msg$, MB_OKCANCEL + MB_ICONQUESTION, "DELETE")
  266.     If rc = IDCANCEL Then
  267.         SetEditMode VIEW_MODE
  268.         Exit Sub
  269.     End If
  270.     rc = DeleteCustomerRec()
  271.     If rc Then
  272.         MsgBox "Delete failed, code: " + Str$(rc)
  273.         Beep
  274.     End If
  275.     rc = GetCustomerRec(DBNEXT)
  276.     If rc Then
  277.         rc = GetCustomerRec(DBLAST)
  278.     End If
  279.     FieldsToForm
  280.     SetEditMode VIEW_MODE
  281. End Sub
  282. Sub ButtonDone_Click ()
  283.     Unload custedit
  284. End Sub
  285. Sub ButtonEdit_Click ()
  286.     screen.MousePointer = POINTER_HOURGLASS
  287.     rc = GetCustomerRecForUpdate()
  288.     If rc Then
  289.         screen.MousePointer = POINTER_DEFAULT
  290.         Exit Sub
  291.     End If
  292.     '
  293.     '  Move the fields to the form again
  294.     '  In a network environment, someone could have
  295.     '  changed the record since last time is was shown
  296.     '
  297.     FieldsToForm
  298.     SetEditMode EDIT_MODE
  299.     screen.MousePointer = POINTER_DEFAULT
  300. End Sub
  301. Sub ButtonFind_Click ()
  302.     FormToFields
  303.     rc = GetCustomerRec(DBKEYED)
  304.     If rc Then
  305.         Exit Sub
  306.     End If
  307.     FieldsToForm
  308. End Sub
  309. Sub ButtonFirst_Click ()
  310.     rc = GetCustomerRec(DBFIRST)
  311.     If rc = DB_OK Then
  312.         FieldsToForm
  313.     End If
  314. End Sub
  315. Sub ButtonLast_Click ()
  316.     rc = GetCustomerRec(DBLAST)
  317.     If rc = DB_OK Then
  318.         FieldsToForm
  319.     End If
  320. End Sub
  321. Sub ButtonNew_Click ()
  322.     Dim numvalue As Long
  323.     SetEditMode ADD_MODE
  324.     savecustrec = custrec
  325.     rc = GetCustomerRec(DBLAST)
  326.     If rc Then
  327.         numvalue = 1
  328.     Else
  329.         numvalue = Val(custrec.custnumber)
  330.     End If
  331.     numvalue = numvalue + 1
  332.     custrec = blankcustrec
  333.     custrec.custnumber = LTrim$(Str$(numvalue))
  334.     FieldsToForm
  335. End Sub
  336. Sub ButtonNext_Click ()
  337.     rc = GetCustomerRec(DBNEXT)
  338.     If rc = DB_OK Then
  339.         FieldsToForm
  340.     End If
  341. End Sub
  342. Sub ButtonOK_Click ()
  343.    FormToFields
  344.     If iMode = ADD_MODE Then
  345.         rc = AddCustomerRec()
  346.     End If
  347.     If iMode = EDIT_MODE Then
  348.         rc = UpdateCustomerRec()
  349.     End If
  350.     '
  351.     '  Assume if one of these failed, a message was
  352.     '  already displayed as part of the function.
  353.     '
  354.     '  What to do if the add or update failed?
  355.     '  For now invoke the CANCEL routine as though
  356.     '  the user clicked the cancel button.
  357.     '
  358.     If rc Then
  359.         ButtonCancel_Click
  360.         Exit Sub
  361.     End If
  362.     '
  363.     '  Return to view mode
  364.     '
  365.     SetEditMode VIEW_MODE
  366. End Sub
  367. Sub ButtonPrior_Click ()
  368.     rc = GetCustomerRec(DBPRIOR)
  369.     If rc = DB_OK Then
  370.         FieldsToForm
  371.     End If
  372. End Sub
  373. Sub FieldsToForm ()
  374.     custnumber.text = custrec.custnumber
  375.     lastname.text = custrec.lastname
  376.     firstname.text = custrec.firstname
  377.     address.text = custrec.address
  378.     city.text = custrec.city
  379.     zip.text = custrec.zip
  380.     tapes_out.caption = Str$(custrec.tapes_out)
  381.     total_spent.caption = Str$(custrec.total_spent)
  382. End Sub
  383. Sub Form_Load ()
  384.     screen.MousePointer = POINTER_HOURGLASS
  385.     rc = GetCustomerRec(DBFIRST)
  386.     If rc = DB_OK Then
  387.         FieldsToForm
  388.     End If
  389.     SetEditMode VIEW_MODE
  390.     screen.MousePointer = POINTER_DEFAULT
  391. End Sub
  392. Sub FormToFields ()
  393.     custrec.custnumber = custnumber.text
  394.     custrec.lastname = lastname.text
  395.     custrec.firstname = firstname.text
  396.     custrec.address = address.text
  397.     custrec.city = city.text
  398.     custrec.zip = zip.text
  399. End Sub
  400. Sub SetEditMode (ByVal mode%)
  401.     If mode = EDIT_MODE Or mode = ADD_MODE Then
  402.         ButtonFirst.visible = False
  403.         ButtonNext.visible = False
  404.         ButtonPrior.visible = False
  405.         ButtonLast.visible = False
  406.         ButtonEdit.visible = False
  407.         ButtonDone.visible = False
  408.         ButtonFind.visible = False
  409.         ButtonNew.visible = False
  410.         ButtonOK.visible = True
  411.         ButtonCancel.visible = True
  412.         If mode = EDIT_MODE Then
  413.             ButtonDelete.visible = True
  414.         End If
  415.     End If
  416.     If mode = VIEW_MODE Then
  417.         '  If a record was locked, unlock it
  418.         '  this may already have been done,
  419.         '  but make the function call again to be safe...
  420.         '
  421.         rc = UnlockRec(CUSTOMER_TABLE)
  422.         '
  423.         ButtonFirst.visible = True
  424.         ButtonNext.visible = True
  425.         ButtonPrior.visible = True
  426.         ButtonLast.visible = True
  427.         ButtonEdit.visible = True
  428.         ButtonDone.visible = True
  429.         ButtonFind.visible = True
  430.         ButtonNew.visible = True
  431.         ButtonOK.visible = False
  432.         ButtonCancel.visible = False
  433.         ButtonDelete.visible = False
  434.     End If
  435.     If mode = ADD_MODE Then
  436.         custnumber.enabled = False
  437.     Else
  438.         custnumber.enabled = True
  439.     End If
  440.     '
  441.     '  Set global value as mode indicator
  442.     '
  443.     iMode = mode
  444. End Sub
  445.